// ENV
// 'development' or 'production'
const env = process.env.NODE_ENV === 'production' ? 'prod' : 'dev'

// development and production host
const hosts = {
  // dev: 'https://api.dotfit.ngrok.milkmeowo.com/api/',
  dev: 'https://test.api.dotfit.milkmeowo.com/api/',
  prod: 'https://api.dotfit.milkmeowo.com/api/'
}

// apis
const api = {
  auth: {
    login: {
      method: 'POST',
      url: 'auth/login'
    },
    loginByMiniProgram: {
      method: 'POST',
      url: 'oauth/mini_program/login'
    },
    logout: {
      method: 'POST',
      url: 'auth/logout'
    }
  },
  user: {
    me: {
      method: 'GET',
      url: 'user/me'
    },
    qrcode: {
      method: 'GET',
      url: 'qrcode'
    }
  },
  bind: {
    mobile: {
      method: 'POST',
      url: 'bind/mobile'
    }
  },
  unbind: {
    mobile: {
      method: 'POST',
      url: 'unbind/mobile'
    }
  },
  files: {
    upload: {
      url: 'files/upload',
      method: 'POST'
    },
    delete: {
      url: 'files/delete',
      method: 'DELETE'
    }
  }
}

const storageKey = {
  accessToken: 'accessToken',
  me: 'me',
  wxUserInfo: 'wxUserInfo'
}

module.exports = {
  env,
  host: hosts[env],
  storageKey,
  api: disposeUrl(api, hosts[env])
}

function disposeUrl (obj, prefix) {
  Object.keys(obj).forEach(v => {
    if (obj[v].url) {
      obj[v].url = prefix + obj[v].url
    } else {
      obj[v] = disposeUrl(obj[v], prefix)
    }
  })

  return obj
}
